package com.bamboo.eduservice.controller.front;

import com.bamboo.commonutils.ResponseEntity;
import com.bamboo.eduservice.entity.EduCourse;
import com.bamboo.eduservice.entity.EduTeacher;
import com.bamboo.eduservice.service.EduCourseService;
import com.bamboo.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jack.wu
 * @version 1.0
 * @date 2020-07-12
 */
@Api(description = "前台首页管理")
@RestController
@RequestMapping("/eduservice/index")
@CrossOrigin
public class FrontIndexController {

    @Resource
    private EduTeacherService teacherService;

    @Resource
    private EduCourseService courseService;

    @ApiOperation(value = "查询前台首页显示数据")
    @GetMapping
    public ResponseEntity getIndexData() {
        // 查询热门讲师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByAsc("sort", "gmt_create");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherQueryWrapper);

        // 查询热门课程
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("view_count", "gmt_create");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(courseQueryWrapper);

        return ResponseEntity.ok().data("teacherList", teacherList).data("courseList", courseList);
    }

}
